<template>
  <div class="wrap">
    <header>
      <div class="headertop">
        <div class="header-img">
          <v-back></v-back>
        </div>
        <h1>
          <v-title></v-title>
        </h1>
        <div class="topradius">
          <i class="iconfont icon-xiaochengxu-gengduo"></i>
          <i class="topborder"></i>
          <i class="iconfont icon-xiaochengxu-guanbi"></i>
        </div>
      </div>
      <div class="headnav">
        <div class="navtop">
          <i class="iconfont icon-dizhi1"></i>
          <img src="../assets/Image/m-index/logo.png" alt="" />
          <div class="search">
            <label for="seachs">
              <i class="iconfont icon-fangdajing"></i>
            </label>
            <input
              @keyup.enter="search1"
              type="search"
              name=""
              id="seachs"
              placeholder="按内容搜索"
              v-model="kw"
            />
          </div>
          <i class="iconfont icon-shangdian"></i>
        </div>
        <nav class="head-nav">
          <ul>
            <li
              @click="goCate(item.id)"
              v-for="item in catelist"
              :key="item.id"
            >
              <a href="javascript:;">{{ item.catename }}</a>
            </li>
          </ul>
        </nav>
      </div>
    </header>
    <div class="content">
      <!--轮播图 -->
      <v-banner></v-banner>
      <div class="index-icon">
        <div>
          <img src="../assets/Image/m-index/icon1.png" alt="" />
          <p>限时秒杀</p>
        </div>
        <div>
          <img src="../assets/Image/m-index/icon2.png" alt="" />
          <p>畅销商品</p>
        </div>
        <div>
          <img src="../assets/Image/m-index/icon3.png" alt="" />
          <p>品质大牌</p>
        </div>
        <div>
          <img src="../assets/Image/m-index/icon4.png" alt="" />
          <p>小u自营</p>
        </div>
        <div>
          <img src="../assets/Image/m-index/icon5.png" alt="" />
          <p>积分商城</p>
        </div>
      </div>
      <div class="bg-gray">
        <div class="index-hot">
          <div class="hot-big">
            <img src="../assets/Image/m-index/big.png" alt="" />
            <div class="big-txt">
              <p><b>限时秒杀</b> <a href="#">查看更多 ></a></p>
              <p>每天0点场，好货秒不停</p>
              <p><i>05</i>：<i>20</i>：<i>48</i></p>
            </div>
          </div>
          <div class="hot-small">
            <div class="small-top">
              <img src="../assets/Image/m-index/small1.png" alt="" />
              <div class="top-txt">
                <p>品牌上新</p>
                <p>9点整，抢大牌</p>
                <p>疯抢红包 ></p>
              </div>
            </div>
            <div class="small-bottom2">
              <img src="../assets/Image/m-index/small2.png" alt="" />
              <div class="top-txt bottom-txt">
                <p>日用好物</p>
                <p>愿君多采撷</p>
                <p>塞满奖券 ></p>
              </div>
            </div>
          </div>
        </div>
        <div class="pre">
          <div class="pre-title">
            <p>双11尖货预购</p>
            <p>畅购全球</p>
          </div>
          <div class="pre-img">
            <img src="../assets/Image/m-index/pre01.png" alt="" />
            <img src="../assets/Image/m-index/pre02.png" alt="" />
            <img src="../assets/Image/m-index/pre03.png" alt="" />
            <img src="../assets/Image/m-index/pre04.png" alt="" />
          </div>
        </div>
      </div>
    </div>
    <!-- 点击切换 -->
    <div class="goods_cont">
      <div class="tab">
        <p :class="flg == 0 ? 'navlink' : ''" @click="tab(0)">热门推荐</p>
        <p :class="flg == 1 ? 'navlink' : ''" @click="tab(1)">上新推荐</p>
        <p :class="flg == 2 ? 'navlink' : ''" @click="tab(2)">所有商品</p>
      </div>
      <ul>
        <li v-for="item in goodslist" :key="item.id" @click="goDetail(item.id)">
          <img :src="item.img" alt="" />
          <div class="info">
            <p>{{ item.goodsname }}</p>
            <p>现价格：￥{{ item.price }}</p>
            <strike>原价格：￥{{ item.market_price }}</strike>
            <p @click.stop="add(item.id)">加入购物车</p>
          </div>
        </li>
      </ul>
    </div>
  </div>
</template>

<script>
import vBanner from "../components/vBanner.vue";
import { getcate, gethortgoods, cartadd } from "../request/api";

export default {
  components: { vBanner },
  data() {
    return {
      flg: 0,
      catelist: [],
      allGoods: [],
      goodslist: [],
      cartadd: [],
      kw: [],
    };
  },
  methods: {
    goDetail(id) {
      this.$router.push("/detail/" + id);
    },
    goCate(id) {
      this.$router.push("/catelist/" + id);
    },
    tab(i) {
      this.goodslist = this.allGoods[i].content;
      this.flg = i;
    },
    search1() {
      this.$router.push("/searchlist/" + this.kw);
    },
    add(id) {
      let islogin = JSON.parse(sessionStorage.getItem("islogin"));
      let obj = {
        uid: islogin.uid,
        goodsid: id,
        num: 1,
      };
      cartadd(obj).then((res) => {
        // console.log(res, "33333");
        if (res.data.code == 200) {
          this.$router.push("/shopping");
          // this.cartadd = res.data.list;
          // console.log(this.cartadd);
      
        }
      });
    },
  },
  mounted() {
    // 首页快速分类导航
    getcate().then((res) => {
      // console.log(res, "成功");
      if (res.data.code == 200) {
        this.catelist = res.data.list;
      }
    });

    // 全部分类
    gethortgoods().then((res) => {
      // console.log(res, "111");
      if (res.data.code == 200) {
        this.allGoods = res.data.list;
        // console.log(this.allGoods);
        this.goodslist = res.data.list[0].content;
      }
    });
  },
};
</script>

<style scoped>
.headnav {
  height: 1.6rem;
  background: linear-gradient(#ff6040 0%, #ff8a80 100%);
  color: #fff;
  padding: 0 0.2rem;
}
.navtop {
  display: flex;
  justify-content: space-between;
  height: 0.88rem;
  align-items: center;
}
.icon-dizhi1:before {
  display: inline-block;
  font-size: 0.44rem;
}
.navtop img {
  width: 1.82rem;
  height: 0.48rem;
}
.search {
  width: 3.4rem;
  height: 0.64rem;
  background-color: #fff;
  color: #999999;
  display: flex;
  justify-content: space-around;
  align-items: center;
  border-radius: 0.32rem;
}

.search input {
  width: 2.4rem;
  height: 0.64rem;
  font-size: 0.32rem;
  border-radius: 0.32rem;
}
.search input::placeholder {
  font-size: 0.32rem;
}
.icon-fangdajing {
  font-size: 0.32rem;
}
.icon-shangdian {
  font-size: 0.4rem;
}
.head-nav ul {
  height: 0.72rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.head-nav li {
  align-self: stretch;
  display: flex;
}
.head-nav ul a {
  position: relative;
  color: #fff;
  font-size: 0.32rem;
  align-self: stretch;
  padding-top: 0.1rem;
}
.icon-caidan {
  font-size: 0.32rem;
}
.head-nav ul a:hover {
  font-weight: bold;
}
.head-nav ul li:hover a:after {
  content: "";
  display: block;
  width: 0.4rem;
  height: 0.06rem;
  background: #fff;
  position: absolute;
  left: 50%;
  margin-left: -0.2rem;
  bottom: 0;
}
.icon-caidan {
  vertical-align: middle;
  position: relative;
  top: -0.04rem;
}

.index-icon {
  display: flex;
  justify-content: space-between;
  margin-bottom: 0.4rem;
  padding: 0 0.2rem;
}
.index-icon div {
  width: 2.16rem;
  text-align: center;
}
.index-icon img {
  width: 0.64rem;
  margin-bottom: 0.1rem;
}
.index-icon div p {
  font-size: 0.2rem;
}
.bg-gray {
  background-color: #f2f2f2;
  padding: 0.17rem 0.2rem;
}
.index-hot {
  display: flex;
  justify-content: space-between;
  margin-bottom: 0.2rem;
}
.hot-big img,
.hot-small img {
  width: 3.5rem;
}
.small-top {
  margin-bottom: 0.1rem;
}
.big-txt p:first-child {
  margin-bottom: 0.2rem;
}
.big-txt p:first-child b {
  font-size: 0.32rem;
  color: #85a642;
  line-height: 0.32rem;
}
.big-txt p:first-child a {
  font-size: 0.2rem;
  color: #333333;
  float: right;
  line-height: 0.32rem;
}
.big-txt p:nth-child(2) {
  font-size: 0.2rem;
  color: #b1cc7a;
  line-height: 0.2rem;
  margin-bottom: 0.08rem;
}
.big-txt p:nth-child(3) i {
  background-image: linear-gradient(180deg, #85a642 0%, #b1cc7a 100%);
  border-radius: 1px;
  padding: 0.06rem 0.08rem;
  display: inline-block;
  font-size: 0.28rem;
  color: #fff;
}
.big-txt p:nth-child(3) {
  display: inline-block;
  color: #85a642;
  font-size: 0.28rem;
}
.hot-big {
  position: relative;
}
.big-txt {
  position: absolute;
  top: 0.22rem;
  width: 3rem;
  left: 0.2rem;
}
.top-txt p:first-child {
  font-size: 0.32rem;
  color: #ff6040;
  line-height: 0.32rem;
  margin-bottom: 0.2rem;
}
.top-txt p:nth-child(2) {
  font-size: 0.2rem;
  color: #ff9580;
  line-height: 0.2rem;
  margin-bottom: 0.08rem;
}
.top-txt p:nth-child(3) {
  width: 1.2rem;
  height: 0.4rem;
  background-image: linear-gradient(180deg, #ff6040 0%, #ff9f80 100%);
  border-radius: 0.04rem 0.24rem 0.24rem 0.04rem;
  font-size: 0.2rem;
  line-height: 0.4rem;
  color: #fff;
  padding-left: 0.08rem;
  box-sizing: border-box;
}
.small-top {
  position: relative;
}
.top-txt {
  position: absolute;
  top: 0.22rem;
  width: 3rem;
  left: 0.2rem;
}
.small-bottom2 {
  position: relative;
}
.bottom-txt p:first-child {
  color: #af40ff;
}
.bottom-txt p:nth-child(2) {
  color: #ca80ff;
}
.bottom-txt p:nth-child(3) {
  background-image: linear-gradient(180deg, #af40ff 0%, #f58cff 100%);
}

.pre {
  background-color: #fff;
}
.pre-title {
  display: flex;
  justify-content: space-around;
  margin-bottom: 0.06rem;
}
.pre-title p {
  font-size: 0.32rem;
  color: #ff6040;
  text-align: center;
  line-height: 0.78rem;
}
.pre-title p:last-child {
  color: #999999;
}
.pre-img {
  display: flex;
  justify-content: space-evenly;
}
.pre-img img {
  width: 1.6rem;
}
.goods_cont .tab .active {
  background-color: rgb(255, 174, 24);
  color: #eee;
}

.goods_cont {
  padding-top: 10px;
  margin-bottom: 70px;
  min-height: 100vh;
}

.goods_cont .tab {
  display: flex;
  justify-content: space-around;
}

.goods_cont .tab p {
  border: 1px solid #eee;
  width: 180px;
  height: 50px;
  text-align: center;
  line-height: 50px;
  font-size: 0.32rem;
}

.goods_cont li {
  padding: 10px;
  border: 1px solid #eee;
  box-shadow: 0 0 5px #000;
  margin: 10px 5px;
  display: flex;
}

.goods_cont li img {
  width: 100px;
  height: 100px;
  margin-top: 25px;
}

.goods_cont li .info p {
  margin-bottom: 15px;
  margin-left: 20px;
}

.goods_cont li .info p:nth-of-type(1) {
  margin-top: 20px;
}

.goods_cont li .info p:nth-of-type(2) {
  color: red;
}

.goods_cont li .info strike {
  color: rgb(182, 180, 180);
  margin-left: 20px;
}

.goods_cont li .info p:nth-of-type(3) {
  width: 80px;
  height: 35px;
  background-color: rgb(255, 166, 0);
  color: #fff;
  line-height: 35px;
  text-align: center;
  border-radius: 5px;
  margin-top: 15px;
}
.navlink {
  color: #fff;
  background-color: orange;
}
</style>
